<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px">
      <el-breadcrumb-item :to="{ path: '/' }">后台管理</el-breadcrumb-item>
      <el-breadcrumb-item>学生管理</el-breadcrumb-item>
      <el-breadcrumb-item>查询退学学生信息</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>
    <el-form :model="queryParam" ref="queryForm" :inline="true">
      <el-form-item label="学生姓名：">
        <el-input v-model="queryParam.searchWord" clearable placeholder="请输入内容"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="searchList()">查询</el-button>
        <el-button type="primary" @click="insert()">添加</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="ID" width="80" align="center"></el-table-column>
      <el-table-column prop="name" label="学生名字" width="100" align="center"></el-table-column>
      <el-table-column prop="major" label="专业" align="center" width="100"></el-table-column>
      <el-table-column prop="cause" label="原因" align="center" width="180"></el-table-column>
      <el-table-column prop="aname" label="奖惩名" align="center"></el-table-column>
      <el-table-column prop="aproject" label="奖惩方案" align="center" width="180"></el-table-column>
      <el-table-column prop="address" label="地址" width="180" align="center"></el-table-column>
      <el-table-column prop="tuition" label="剩余学费"  align="center"></el-table-column>
      <el-table-column prop="created" label="退学时间" align="center" width="180"></el-table-column>
      <el-table-column label="操作"  align="center">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" size="mini" circle
                     @click="handleEdit(scope.row)"></el-button>
          <el-button type="danger" icon="el-icon-delete" size="mini" circle
                     @click="openDeleteConfirm(scope.row)"></el-button>
<!--          <el-button type="info" icon="el-icon-thumb" size="mini" @click="dropStudentDetail(scope.row)"></el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <div class="block">
      <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="pageNum"
              :page-sizes="[2, 4, 6, 25]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
      </el-pagination>
    </div>
    <!-- 弹出的编辑相册的对话框 -->
    <el-dialog title="修改学生" :visible.sync="dialogFormVisible">
      <el-form :model="ruleForm">
        <el-form-item label="学生名字" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.name" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="原因" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.cause"></el-input>
        </el-form-item>
        <el-form-item label="剩余学费" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.tuition"></el-input>
        </el-form-item>
        <el-form-item label="奖惩名" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.aname"></el-input>
        </el-form-item>
        <el-form-item label="奖惩方案" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.aproject"></el-input>
        </el-form-item>
        <el-form-item label="地址" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.address"></el-input>
        </el-form-item>
        <el-form-item label="退学时间:" :label-width="formLabelWidth" >
          <el-date-picker
                  v-model="ruleForm.created"
                  type="date"
                  placeholder="选择日期">
          </el-date-picker>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitEdit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>

</template>



<script>
export default {
  data() {
    return {
      isShow:true,
      dialogImageUrl: '',
      dialogVisible: false,
      /*表格查询*/
      queryParam: {
        searchWord: '',

      },
      pageNum: 1, // 当前第几页
      pageSize: 2,  // 每一个页面限制5条数据
      // 数据总数
      total: 0,
      tableData: [],
      dialogFormVisible: false,
      ruleForm: {
        id:'',
        name: '',
        cause: "",
        tuition: "",
        address: "",
        aname:'',
        aproject:'',
        created: "",

      },
      formLabelWidth: '120px'
    };
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.pageNum = 2;
      this.loadDropStudentList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNum=val;
      this.loadDropStudentList();
    },
    dropStudentDetail(dropStudent){
      location.href='/sys-admin/main/student/dropDetail?id='+dropStudent.id;
    },
    //点击当前页面触发
    changeCurrent(val) {
      console.log(val);
      this.queryParam.current = val;
      this.total = val;
      this.loadDropStudentList();
    },
    searchList() {
      this.loadDropStudentList();
    },
    insert(){
      location.href='/sys-admin/main/student/dropInsert';
    },
    loadDropStudentList() {
      this.axios.get("http://localhost:9801/dropStudents/selectPage", {
        params: {
          searchWord: this.queryParam.searchWord,
          pageSize:this.pageSize,
          pageNum:this.pageNum,
          total:this.total
        }
      }).then((response) => {
        console.log(response);
        this.tableData = response.data.data.data;
        this.tableData.total = response.data.data.total;
      })
    },
    submitEdit() {
      let url = 'http://localhost:9801/dropStudents/' + this.ruleForm.id +'/update';
      console.log('url = ' + url);
      let formData = this.qs.stringify(this.ruleForm);
      console.log('formData = ' + formData);

      this.axios
              .post(url, formData).then((response) => {
        let responseBody = response.data;
        if (responseBody.state == 20000) {
          this.$message({
            message: '修改学生成功！',
            type: 'success'
          });
          this.dialogFormVisible = false;
          this.loadDropStudentList();
        } else if (responseBody.state == 40900) {
          this.$message.error(responseBody.message);
        } else {
          this.$message.error(responseBody.message);
          this.dialogFormVisible = false;
          this.loadDropStudentList();
        }
      });
    },
    handleEdit(dropStudent) {
      let message = '您正在尝试编辑【' + dropStudent.id + '-' + dropStudent.name + '】的学生详情……';
      console.log(message);
      // this.dialogFormVisible = true;
      // this.ruleForm = album;
      let url = 'http://localhost:9801/dropStudents/' + dropStudent.id;
      console.log(url);
      this.axios
              .get(url).then((response) => {
        let responseBody = response.data;
        if (responseBody.state == 20000) {
          this.ruleForm = responseBody.data;
          this.dialogFormVisible = true;
        } else {
          this.$message.error(responseBody.message);
          this.loadDropStudentList();
        }
      });
    },
    openDeleteConfirm(dropStudent) {
      let title = '提示';
      let message = '此操作将永久删除【' + dropStudent.name + '】学生，是否继续？';
      this.$confirm(message, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(dropStudent);
      }).catch(() => {
      });
    },
    handleDelete(dropStudent) {
      let url = 'http://localhost:9801/dropStudents/' + dropStudent.id + '/delete';
      console.log('url = ' + url);
      this.axios.post(url).then((response) => {
        let responseBody = response.data;
        console.log(responseBody);
        if (responseBody.state != 20000) {
          this.$message.error(responseBody.message);
        }
        this.loadDropStudentList();
      });
    },
  },
  mounted() {
    this.loadDropStudentList();
  }
}
</script>